home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / misc.562 < prev    next >
Text File  |  1992-02-06  |  2KB  |  36 lines

  1. {\rtf0\ansi{\fonttbl\f2\fnil Times-Roman;\f3\fmodern Courier;\f1\fswiss Helvetica;}
  2. \paperw11760
  3. \paperh7200
  4. \margl120
  5. \margr120
  6. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f2\b0\i0\ul0\fs28 dynamic loader archive library\
  7.     \
  8. Q:  I have an archive which contains an Objective-C class with all of its associated methods. How can I dynamically load the object from the library into my app at run-time?\
  9.  
  10. \i     \
  11.  
  12. \i0 A:  This discussion assumes you're running release 2.0.  Let's say that the symbol for the class 
  13. \b Cat
  14. \b0  is defined in the library 
  15. \b pets.a
  16. \b0 .  Calling rld_load() with pets.a as the only file argument will not cause the Cat symbol to be loaded unless there is an unresolved reference to the Cat object within the application.  Creating an unresolved reference to this object at runtime requires some sleight of hand.\
  17. \
  18. When the application realizes that it requires the Cat object it needs to fork a process with the following ld(1) command:\
  19. \
  20.  
  21. \f3\fs24     ld -r -u .objc_class_name_Cat  -w -o Cat.o\
  22.  
  23. \f2\fs28     \
  24. This will create a .o file with an unresolved reference to the Cat object as understood by the loader. The -w option will supress warnings (as this is an atypical use for ld). The -r option causes the .o file to be relocatable.  The -u <symbol> forces an undefined entry in the symbol table.\
  25. \
  26. Now that this file exists it may be passed to rld_load simultaneously with the pets.a library. The Cat.o file should appear before the pets.a file in the same way as it would using the command line ld.\
  27. \
  28. Once the object has been loaded the Cat.o file may be removed using unlink(2).\
  29. \
  30. QA562                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              \
  31. \
  32. Not valid for 1.0\
  33. Valid for 2.0\
  34. \
  35.  
  36.